﻿using MediatR;
using SheepCultivation.Common.Domain.Week2;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.BuildingD
{
    public class ColumnsSeachHandler : IRequestHandler<ColumnsSeachCommon, Result>
    {
        #region 仓储
        /// <summary>
        /// 仓储
        /// </summary>
        public readonly IBaseRepository<Building> BuildingRepository;
        public readonly IBaseRepository<BuildingType> BuildingTypeRepository;
        public readonly IBaseRepository<Columns> ColumnsRepository;
        public readonly ILogger<ColumnsSeachHandler> logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="buildingRepository">栋舍信息</param>
        /// <param name="buildingTypeRepository">栋舍类型</param>
        /// <param name="logger">日志</param>
        public ColumnsSeachHandler(IBaseRepository<Building> buildingRepository, IBaseRepository<BuildingType> buildingTypeRepository, IBaseRepository<Columns> ColumnsRepository, ILogger<ColumnsSeachHandler> logger)
        {
            BuildingRepository = buildingRepository;
            BuildingTypeRepository = buildingTypeRepository;
            this.logger = logger;
            this.ColumnsRepository = ColumnsRepository;
        }
        #endregion

        #region 下拉框栏位
        /// <summary>
        /// 下拉框 栏位
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(ColumnsSeachCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var list = ColumnsRepository.GetAll().Where(x => x.BuildingId == request.BuildingId).ToList();

                result.Code = (int)CommonEnumCode.success;
                result.Data = list;
                result.Msg = "下拉框栏位成功";
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
        #endregion
    }
}
